<?
require_once('../../inc/common.php');
require_once('../../bin/db.php');
$db= new MySQL_Class();
$db->Create();
$sendmail=0;

if (isset($_POST['action'])&&$_POST['action']=='update') {
	$stock=$_POST['addstock'];
	$admin=$_SESSION['admin_name'];
	$id=$_POST['id'];
	
	$sql="update pro_basic set stock=stock+$stock where id=$id;";
	$db->Query($sql);
	if ($db->result) {
		$t=time();
		$db->Query("insert into pro_transaction (pid,trans_time,amount,person) values ($id,$t,$stock,'$admin')");
		$sendmail=1;
	} 
	if(isset($_POST["even"])&&$_POST["even"]=='search')
	{
		$strPara="&Search=".$_POST["keyword"]."&action=search&ord=".$_POST["ord"]."&sort=".$_POST["sort"];
	}
	else
	{
		$strPara="&cat=".$_POST['cat']."&ord=".$_POST["ord"]."&sort=".$_POST["sort"];
	}	
	echo "<script>
		window.opener.location.href='product_menu.php?Start_Num=".$_POST['Start_Num'].$strPara."'; 
		window.close();
	</script>";
	exit();

}

$id=$_GET['id'];

$sql="select name,brand,code,stock from pro_basic where id=$id";
$db->Query($sql);
$rec=mysql_fetch_object($db->result);

/*
if ($sendmail) {
		$sql="select name,email from user_profile where alert02='y'";
		$db->Query($sql);
		if ($res=$db->result) {
			$tomail='';
			while ($record=mysql_fetch_object($res)) {
				if ($tomail) $tomail.=",";
				$tomail.='"'.$record->name.'" <'.$record->email.'>';
			}
		}
		$mail='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Re-stock Alert</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<style type="text/css">
body {font-size: 10pt; font-family: Arial }
td {font-size: 10pt; font-family: Arial }
</style>
</head>
<body bgcolor="#FFFFFF">
<table width="600" border="0" cellspacing="0" cellpadding="1">
  <tr>
    <td align="right"><table width="180" border="0" cellpadding="1" cellspacing="0">
  <tr>
    <td bgcolor="#000000"><table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
        <tr>
                <td align="center"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Jonesky 
                  Limited </strong></font></td>
        </tr>
      </table></td>
  </tr>
</table></td>
  </tr>
</table>
<br>
<font size="2" face="Arial, Helvetica, sans-serif"><br>
Dear all,<br>
<p>Re-stock Alert<br><br>

Administrator : '.$admin.'<br> 
Product Code  : '.$rec->code.'<br>
Product Name  : '.$rec->name.' '.$rec->brand.'<br>
Current Stock : '.$rec->stock.' ('.$stock.')<br></p>
</font> 
<br>
<br>
<p>&nbsp;</p>
<p><font size="2" face="Arial, Helvetica, sans-serif"><strong>Jonesky Limited</strong><br>
  Unit 1201, 1205-8, 12/F Westlands Centre,<br>
  20 Westlands Road<br>
  Quarry Bay<br>
  Hong Kong<br>
  Tel: 2561-8172<br>
  Fax:2565-9326<br>
  <a href="http://www.comicsworld.com">www.comicsworld.com </a></font></p>
<p>&nbsp; </p>
</body>
</html>';
				myMail('Re-stock Alert',$mail,'',$tomail);
}
*/

?><html><head><title>Add stock</title>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 3px;
	margin-right: 3px;
	margin-bottom: 3px;
}
-->
</style>
<link href="../../inc/css.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
<form name="form1" method="post" action=""><table width="100%"  border="0" cellspacing="0" cellpadding="2">
  <tr bgcolor="#FFFFFF">
    <td colspan="2" class="listbk1">Add Stock </td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td width="100"><div align="right">Code : </div></td>
    <td><?=$rec->code?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td><div align="right">Name :</div></td>
    <td><?=$rec->name.'<br>'.$rec->brand?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td><div align="right">Current Stock : </div></td>
    <td><?=$rec->stock?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td><div align="right">Add :</div></td>
    <td><input name="addstock" type="text" id="addstock" value="0"></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td><input name="Submit" type="submit" onClick="MM_validateForm('addstock','','RisNum');return document.MM_returnValue" value="Submit"> 
       <input type="reset" name="Reset" value="Reset">
      <input name="action" type="hidden" id="submit" value="update"><input name="id" type="hidden" id="id" value="<?=$id?>">
      <input name="even" type="hidden" id="even" value="<?=$_GET["even"]?>">
      <input name="keyword" type="hidden" id="keyword" value="<?=$_GET["keyword"]?>">
	  <input name="ord" type="hidden" id="ord" value="<?=$_GET["ord"]?>">
	  <input name="sort" type="hidden" id="sort" value="<?=$_GET["sort"]?>">
		<input name="Start_Num" type="hidden" id="Start_Num" value="<?=$_GET['Start_Num']?>">
		<input name="cat" type="hidden" id="cat" value="<?=$_GET['cat']?>">
	  </td>
  </tr>
</table>
</form>
</body>
</html>